﻿
<ul id="tag-tree-id">    
</ul>

<script type="text/javascript">

    function addTag(node, parentTag) {

        var item = $("<li>");

        var nodeText = (node.Tag != null) ? node.Tag.Name : "root";
        item.append("<span>" + nodeText + "</span>");
        
        if(node.Childs.length != 0) {

            var subItems = $("<ul>");            

            for (var subNode in node.Childs) {
                addTag(node.Childs[subNode], subItems)
            }

            item.append(subItems);
        }

        parentTag.append(item);
    }



    $(document).ready(function () {


        $.getJSON("/Home/TreeTags", null,
            function (json) {

                var node = json;
                var parentTag = $("#tag-tree-id");

                addTag(node, parentTag);

                parentTag.treeview();
            }
        );
        
    });
</script>